package dao.impl;

import java.util.ArrayList;

import javax.persistence.EntityTransaction;

import dao.IActionDAO;
import entities.Action;

public class ActionDAO implements IActionDAO {

	private HibernateBase hibernateBase;

	public ActionDAO() {
		hibernateBase = HibernateBase.getInstance();
	}

	@Override
	public void init() {
		hibernateBase.init();
	}

	@Override
	public void close() {
		hibernateBase.close();
	}

	@Override
	public boolean create(Action action) {
		boolean status = false;

		EntityTransaction tx = hibernateBase.getManager().getTransaction();
		try {
			tx.begin();
			hibernateBase.getManager().persist(action);
			tx.commit();
			status = true;
		} catch (Exception e) {
			e.printStackTrace();
			if (tx.isActive()) {
				tx.rollback();
			}
		}
		return status;
	}

	@Override
	public boolean delete(Action action) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public ArrayList<Action> getAll() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Action getBy(long id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean update(Action action) {
		// TODO Auto-generated method stub
		return false;
	}

}
